package com.moleq.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.moleq.base.MoleQBaseDialog;
import com.moleq.base.OnResultListener;
import com.moleq.mgpos.widget.NumberPad;
import com.moleq.mgpos.widget.NumberPadButton;
import com.moleq.mgpos.widget.NumberPadForPayment;
import com.moleq.mgpos.widget.NumberPadForPayment.NumberPadListener;
import com.moleq.mgpos.activities.R;

public class InputQtyInfoDialog extends MoleQBaseDialog {

	private OnResultListener mOnResultListener;
	private Button btnConfirm;
	private Button btnClose;
	private NumberPadForPayment mNumPad;

	private Button.OnClickListener mOnClickListener = new Button.OnClickListener() {

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			switch (arg0.getId()) {
			case R.id.buttonInputQtyInfoClose:
				dismiss();
				break;
			case R.id.buttonInputQtyInfoConfirm:
				String strAuth = mNumPad.getBuffer();
				if (strAuth != null && !strAuth.equals("")) {
					
					if (strAuth.length() > 2) {
						MessageBox.show(mContext, "The Qty is too large.");
						return;
					}
					onCloseWithReturn(strAuth);
				}

				break;
			}
		}

	};
	
	private NumberPadListener mNumPadListener = new NumberPadListener(){

		@Override
		public void onClick(NumberPadButton button) {
			switch(button){
			case ENTER:
				
				break;
			}
			
		}
		
	};
	
	public void onCloseWithReturn(Object obj){
		mOnResultListener.onReturnValue(0,obj);
		dismiss();
	}


	public InputQtyInfoDialog(Context context, Object base) {
		super(context,R.style.dialog,base);
		constructor(context,base);
	}
	
	public InputQtyInfoDialog(Context context, int theme,Object base) {
		super(context, theme,base);
		constructor(context,base);
	}
	
	private void constructor(Context context,Object base) {
		mContext = context;
		mOnResultListener = (OnResultListener) base;
	}
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.dialog_input_qty_info);
		this.setCancelable(false);

		btnConfirm = (Button) findViewById(R.id.buttonInputQtyInfoConfirm);
		btnConfirm.setOnClickListener(mOnClickListener);

		btnClose = (Button) findViewById(R.id.buttonInputQtyInfoClose);
		btnClose.setOnClickListener(mOnClickListener);

		mNumPad = (NumberPadForPayment) findViewById(R.id.authNumPad);
		mNumPad.setNumberPadListener(mNumPadListener);
		mNumPad.setStyle(NumberPadForPayment.NO_ENTER_DOT_STYLE);
	}
	
	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		
		mNumPad.reset();
		mNumPad.requestFocusFromTouch();
		
	}
	
}
